package com.tensquare.article.controller;

import com.tensquare.article.pojo.Comment;
import com.tensquare.article.service.CommentService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by WF on 2019/9/19 10:58
 */
@RestController
@RequestMapping("comment")
@CrossOrigin
public class CommentController {

    @Autowired
    private CommentService commentService;
    //1.添加评论
    @PostMapping
    public Result add(@RequestBody Comment comment){
        commentService.add(comment);
        return new Result(true,StatusCode.OK,"添加成功！");
    }
    //2.根据id查询评论
    @GetMapping("/article/{articleid}")
    public Result findByArticleid(@PathVariable String articleid){
        return new Result(true, StatusCode.OK, "查询成功",
                commentService.findByArticleid(articleid));
    }
}
